package com.itheima.health.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.health.constant.MessageConstant;
import com.itheima.health.entity.PageResult;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.Menu;
import com.itheima.health.pojo.Permission;
import com.itheima.health.pojo.Role;
import com.itheima.health.service.MenuService;
import com.itheima.health.service.PermissionService;
import com.itheima.health.service.RoleService;
import com.itheima.health.vo.RoleVo;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/role")
public class RoleController {

    @Reference
    private RoleService roleService;

    @Reference
    private MenuService menuService;

    @Reference
    private PermissionService permissionService;

    /**
     * 分页查询角色
     * @param queryPageBean
     * @return
     */
    @PostMapping("/findPage")
    public Result findPage(@RequestBody QueryPageBean queryPageBean) {
        PageResult<Role> pageResult = roleService.findPage(queryPageBean);
        return new Result(true, MessageConstant.QUERY_ROLE_SUCCESS, pageResult);
    }

    @GetMapping("/findAll")
    public Result findAll() {
        List<Role> roleList = roleService.findAll();
        return new Result(true, MessageConstant.QUERY_ROLE_SUCCESS, roleList);
    }

    @GetMapping("/findById")
    public Result findById(int roleId) {
        Role role = roleService.findById(roleId);
        return new Result(true, MessageConstant.QUERY_ROLE_SUCCESS, role);
    }


    /**
     * 添加角色
     * @param roleVo
     * @return
     */
    @PostMapping("/add")
    public Result add(@RequestBody RoleVo roleVo) {
        roleService.add(roleVo);

        return new Result(true, MessageConstant.ADD_ROLE_SUCCESS);
    }

    /**
     * 更新角色
     * @param roleVo
     * @return
     */
    @PostMapping("/update")
    public Result update(@RequestBody RoleVo roleVo) {
        roleService.update(roleVo);

        return new Result(true, MessageConstant.UPDATE_ROLE_SUCCESS);
    }


    /**
     * 删除角色
     * @param id
     * @return
     */
    @PostMapping("/deleteById")
    public Result deleteById(int id) {
        roleService.deleteById(id);

        return new Result(true, MessageConstant.DELETE_ROLE_SUCCESS);
    }
}
